import requests #pip3 install requests
from bs4 import BeautifulSoup # pip3 install bs4

url = 'https://list.jd.com/list.html?cat=9987,653,655'
h = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36'}
# r = requests.get(url, headers=h)
html =  driver.page_source

# soup = BeautifulSoup(r.content, 'html5lib')
# J_goodsList = soup.find('div', id='J_goodsList')
# cell_phones = J_goodsList.find_all('li', {'class':'gl-item'})
# cell_phone = cell_phones[0]

phones = []

# https://list.jd.com/list.html?cat=9987%2C653%2C655&page=1&s=117&click=0

for i in range(1, 10+1):
    url = 'https://list.jd.com/list.html?cat=9987%2C653%2C655&page={}&s=117&click=0'.format(i)

    r = requests.get(url, headers=h)
    soup = BeautifulSoup(r.content, 'html5lib')
    J_goodsList = soup.find('div', id='J_goodsList')
    cell_phones = J_goodsList.find_all('li', {'class':'gl-item'})

    for cell_phone in cell_phones:
        phone = {}
        # 编号
        phone['id'] = cell_phone['data-sku']
        # 名字
        phone['name'] = cell_phone.find('div', class_='p-name p-name-type-3').find('em').text
        # 价格
        phone['price'] = cell_phone.find('div', class_='p-price').find('i').text
        # 图片网址
        phone['img'] = cell_phone.find('div', class_='p-img').find('a').find('img')['data-lazy-img']
        phones.append(phone)

print(len(phones))